/*******************************************************************************
 * Package: com.hngtrust.iir.company.service.impl
 * Type:    FinancialScoringServiceImpl
 * Date:    2021/4/25 19:25
 *
 * Copyright (c) 2021 HUANENG GUICHENG TRUST CORP.,LTD All Rights Reserved.
 *
 * You may not use this file except in compliance with the License.
 *******************************************************************************/
package com.hngtrust.iir.company.service.impl;

import com.hngtrust.framework.id.service.MyIdGenerator;
import com.hngtrust.iir.base.entity.Speechcraft;
import com.hngtrust.iir.base.service.SpeechcraftService;
import com.hngtrust.iir.company.controller.vo.CompFinanceTrendReqVO;
import com.hngtrust.iir.company.controller.vo.ListCompareCompaniesRespVO;
import com.hngtrust.iir.company.controller.vo.ListComprehensiveDataRespVO;
import com.hngtrust.iir.company.controller.vo.ListComprehensiveRespVO;
import com.hngtrust.iir.company.controller.vo.ListContrastReqVO;
import com.hngtrust.iir.company.controller.vo.ListContrastRespVO;
import com.hngtrust.iir.company.controller.vo.ListContrastTrendAverageRespVO;
import com.hngtrust.iir.company.controller.vo.ListContrastTrendDataRespVO;
import com.hngtrust.iir.company.controller.vo.ListContrastTrendReqVO;
import com.hngtrust.iir.company.controller.vo.ListContrastTrendRespVO;
import com.hngtrust.iir.company.controller.vo.ListFiancialDataReqVo;
import com.hngtrust.iir.company.controller.vo.ListFiancialReqVo;
import com.hngtrust.iir.company.controller.vo.ListFinanceGradeAvgRespVO;
import com.hngtrust.iir.company.controller.vo.ListFinanceGradeEvaluateRespVO;
import com.hngtrust.iir.company.controller.vo.ListFinanceGradeRespVO;
import com.hngtrust.iir.company.controller.vo.ListFinanceGradeTrendRespRespVO;
import com.hngtrust.iir.company.controller.vo.ListFinanceGradeTrendValueRespRespVO;
import com.hngtrust.iir.company.controller.vo.ListFinanceGradeValueRespVO;
import com.hngtrust.iir.company.entity.CompFinanceEvaluate;
import com.hngtrust.iir.company.entity.CompFinanceGrade;
import com.hngtrust.iir.company.entity.Company;
import com.hngtrust.iir.company.entity.IndustryPerformance;
import com.hngtrust.iir.company.entity.ShareFinancialIndex;
import com.hngtrust.iir.company.entity.ShareIndicatorIndex;
import com.hngtrust.iir.company.service.CompFinanceEvaluateService;
import com.hngtrust.iir.company.service.CompFinanceGradeService;
import com.hngtrust.iir.company.service.CompanyService;
import com.hngtrust.iir.company.service.FinancialScoringService;
import com.hngtrust.iir.company.service.IndustryPerformanceService;
import com.hngtrust.iir.company.service.ShareFinancialIndexService;
import com.hngtrust.iir.company.service.ShareIndicatorIndexService;
import com.hngtrust.iir.constant.Constant;
import com.hngtrust.iir.exception.IirErrorType;
import com.hngtrust.iir.exception.IirException;
import com.hngtrust.iir.util.ListUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * 财务评价实现类
 *
 * @author Wanghan
 * @date 2021/4/25 19:25
 */

@Service
public class FinancialScoringServiceImpl implements FinancialScoringService {
    
    //财务综合评分
    @Autowired
    private CompFinanceGradeService compFinanceGradeService;
    
    //财务评价表
    @Autowired
    private CompFinanceEvaluateService compFinanceEvaluateService;
    
    //指标话术配置表
    @Autowired
    private SpeechcraftService speechcraftService;
    
    //ID生成
    @Autowired
    private MyIdGenerator myIdGenerator;
    
    @Autowired
    private CompanyService companyService;
    
    @Autowired
    private ShareIndicatorIndexService shareIndicatorIndexService;
    
    @Autowired
    private ShareFinancialIndexService shareFinancialIndexService;
    
    @Autowired
    private IndustryPerformanceService industryPerformanceService;

    //流动比率的行业平均值(保留4位小数)
    BigDecimal currentRateavg = new BigDecimal(1.3).setScale(4, BigDecimal.ROUND_DOWN);

    /**
     * 财务综合评分
     */
    public List<ListComprehensiveRespVO> getComprehensiveRespVO(ListFiancialReqVo req) {
        if (!(req.getCompId() > 0L)) {
            throw new IirException(IirErrorType.INTFACE_PARAMS_ERROR, "ID");
        }
        List<ListComprehensiveRespVO>  resp = new ArrayList<>();
        List<ListComprehensiveDataRespVO> listComprehensiveDataRespVO = new ArrayList<>();
        
        CompFinanceGrade compFinanceGrade = new CompFinanceGrade();
        compFinanceGrade.setCompId(req.getCompId());
        List<Integer> years = getFinanceGradeByYear();
        compFinanceGrade.setStatus(Constant.DEFAULT_STATUS_NORMAL);
        for(int year:years){
            compFinanceGrade.setYear(year);
            List<CompFinanceGrade> compFinanceGradeList = compFinanceGradeService.queryList(compFinanceGrade);
            if (compFinanceGradeList != null && !compFinanceGradeList.isEmpty()) {
                ListComprehensiveDataRespVO comprehensiveDataRespVO = new ListComprehensiveDataRespVO();
                comprehensiveDataRespVO = getSpeechcraftByTypeRespVO(compFinanceGradeList.get(0));
                listComprehensiveDataRespVO.add(comprehensiveDataRespVO);
            }else{
                ListComprehensiveDataRespVO comprehensiveDataRespVO = new ListComprehensiveDataRespVO();
                comprehensiveDataRespVO.setCompId(req.getCompId());
                comprehensiveDataRespVO.setYear(year);
                listComprehensiveDataRespVO.add(comprehensiveDataRespVO);
            }
        }
        ListUtil<ListComprehensiveRespVO> listUtil = BeanUtils.instantiateClass(ListUtil.class);
        listUtil.copyList(listComprehensiveDataRespVO, resp, ListComprehensiveRespVO.class);
        return resp;
    }
    
    /**
     * 财务综合评分每年数据
     */
    public ListComprehensiveDataRespVO getSpeechcraftByTypeRespVO(CompFinanceGrade financeGrade) {
        List<CompFinanceEvaluate> compFinanceEvaluateList = new ArrayList<>();
        ListComprehensiveDataRespVO listComprehensiveDataRespVO = new ListComprehensiveDataRespVO();
        listComprehensiveDataRespVO.setId(financeGrade.getId());//Id
        listComprehensiveDataRespVO.setCompId(financeGrade.getCompId());//公司Id
        listComprehensiveDataRespVO.setYear(financeGrade.getYear());//年份
        listComprehensiveDataRespVO.setProfitAbility(financeGrade.getProfitAbility());//盈利能力得分
        listComprehensiveDataRespVO.setSolvency(financeGrade.getSolvency());//偿债能力得分
        listComprehensiveDataRespVO.setOperationAbility(financeGrade.getOperationAbility());//营运能力得分
        listComprehensiveDataRespVO.setGrowAbility(financeGrade.getGrowAbility());//成长能力得分
        listComprehensiveDataRespVO.setCash(financeGrade.getCash());//现金流量得分
        if(null != financeGrade.getTotalScore()){
            listComprehensiveDataRespVO.setTotalScore(financeGrade.getTotalScore().setScale(2,BigDecimal.ROUND_HALF_DOWN));//综合得分
        }else{
            listComprehensiveDataRespVO.setTotalScore(null);
        }
        CompFinanceEvaluate compFinanceEvaluate = new CompFinanceEvaluate();

        compFinanceEvaluate.setFinanceGradeId(financeGrade.getId());
        compFinanceEvaluateList = compFinanceEvaluateService.queryList(compFinanceEvaluate);
        if (compFinanceEvaluateList != null && !compFinanceEvaluateList.isEmpty()) {
            listComprehensiveDataRespVO.setProfitAbilityType(getSpeechcraftByType(compFinanceEvaluateList.get(0).getProfitAbility()));//盈利能力模块评价
            listComprehensiveDataRespVO.setSolvencyType(getSpeechcraftByType(compFinanceEvaluateList.get(0).getSolvency()));//偿债能力模块评价
            listComprehensiveDataRespVO.setOperationAbilityType(getSpeechcraftByType(compFinanceEvaluateList.get(0).getOperationAbility()));//营运能力模块评价
            listComprehensiveDataRespVO.setGrowAbilityType(getSpeechcraftByType(compFinanceEvaluateList.get(0).getGrowAbility()));//成长能力模块评价
            listComprehensiveDataRespVO.setCashType(getSpeechcraftByType(compFinanceEvaluateList.get(0).getCash()));//现金流量模块评价
            listComprehensiveDataRespVO.setTotalScoreType(getSpeechcraftByType(compFinanceEvaluateList.get(0).getTotalScore()));//综合得分模块评价
        }
        return listComprehensiveDataRespVO;
    }
    
    /**
     * 评分详情
     */
    public List<ListFinanceGradeRespVO> getFinanceGradeRespVO(ListFiancialDataReqVo req) {
        CompFinanceGrade compFinanceGrade = new CompFinanceGrade();
        ListFinanceGradeRespVO listFinanceGradeRespVO = new ListFinanceGradeRespVO();
        compFinanceGrade.setCompId(req.getCompId());
        compFinanceGrade.setYear(req.getYear());
        //财务综合评分详情指标值
        List<CompFinanceGrade> compFinanceGradeList = compFinanceGradeService.queryList(compFinanceGrade);
        List<ListFinanceGradeValueRespVO> listFinanceGradeValueRespVO = new ArrayList<>();
        ListFinanceGradeValueRespVO financeGradeValueRespVO = new ListFinanceGradeValueRespVO();
        if(compFinanceGradeList != null && !compFinanceGradeList.isEmpty()){
            for (CompFinanceGrade financeGrade : compFinanceGradeList) {
                listFinanceGradeRespVO.setId(financeGrade.getId());//Id
                listFinanceGradeRespVO.setCompId(financeGrade.getCompId());//公司Id
                listFinanceGradeRespVO.setYear(financeGrade.getYear());//年份
                financeGradeValueRespVO.setTotalRoa(financeGrade.getTotalRoa());//总资产报酬率
                financeGradeValueRespVO.setNetRoa(financeGrade.getNetRoa());//净资产收益率
                financeGradeValueRespVO.setSalesMargin(financeGrade.getSalesMargin());//销售（营业）利润率
                financeGradeValueRespVO.setNetMargin(financeGrade.getNetMargin());//成本费用利润率
                financeGradeValueRespVO.setCurrentRate(financeGrade.getCurrentRate());//流动比率
                financeGradeValueRespVO.setQuickRate(financeGrade.getQuickRate());//速动比率
                financeGradeValueRespVO.setLoar(financeGrade.getLoar());//资产负债率
                financeGradeValueRespVO.setEbitMultiple(financeGrade.getEbitMultiple());//利息保障倍数
                financeGradeValueRespVO.setReceivableRate(financeGrade.getReceivableRate());//应收款项周转率
                financeGradeValueRespVO.setInventoryTurnover(financeGrade.getInventoryTurnover());//存货周转率
                financeGradeValueRespVO.setCirculatingRate(financeGrade.getCirculatingRate());//流动资产周转率
                financeGradeValueRespVO.setTotalAssetRate(financeGrade.getTotalAssetRate());//总资产周转率
                financeGradeValueRespVO.setSalesGrow(financeGrade.getSalesGrow());//销售（营业）增长率
                financeGradeValueRespVO.setProfitGrow(financeGrade.getProfitGrow());//销售（营业）利润增长率
                financeGradeValueRespVO.setTotalAssetGrow(financeGrade.getTotalAssetGrow());//总资产增长率
                financeGradeValueRespVO.setCapitalGrow(financeGrade.getCapitalGrow());//资本保值增长率
                financeGradeValueRespVO.setCashDebt(financeGrade.getCashDebt());//经营性净现金流／流动负债
                financeGradeValueRespVO.setCashTotalDebt(financeGrade.getCashTotalDebt());//经营性净现金流／总产总额
                financeGradeValueRespVO.setCashProfits(financeGrade.getCashProfits());//经营性现金流／净利润
                listFinanceGradeValueRespVO.add(financeGradeValueRespVO);
                listFinanceGradeRespVO.setListFinanceGradeValueRespVO(listFinanceGradeValueRespVO);
                //财务综合评分详情指标评价
                CompFinanceEvaluate compFinanceEvaluate = new CompFinanceEvaluate();
                compFinanceEvaluate.setFinanceGradeId(financeGrade.getId());
                List<CompFinanceEvaluate> compFinanceEvaluateList = compFinanceEvaluateService.queryList(compFinanceEvaluate);
                if(null != compFinanceEvaluateList && !compFinanceEvaluateList.isEmpty()){
                    for (CompFinanceEvaluate financeEvaluate : compFinanceEvaluateList) {
                        if(financeEvaluate != null){
                            List<ListFinanceGradeEvaluateRespVO> listFinanceGradeEvaluateRespVO = new ArrayList<>();
                            ListFinanceGradeEvaluateRespVO financeGradeEvaluateRespVO = new ListFinanceGradeEvaluateRespVO();
                            financeGradeEvaluateRespVO.setTotalRoa(getSpeechcraftByType(financeEvaluate.getTotalRoa()));//总资产报酬率
                            financeGradeEvaluateRespVO.setNetRoa(getSpeechcraftByType(financeEvaluate.getNetRoa()));//净资产收益率
                            financeGradeEvaluateRespVO.setSalesMargin(getSpeechcraftByType(financeEvaluate.getSalesMargin()));//销售（营业）利润率
                            financeGradeEvaluateRespVO.setNetMargin(getSpeechcraftByType(financeEvaluate.getNetMargin()));//成本费用利润率
                            String profitAbilityConclusion = getSpeechcraftByContent(financeEvaluate.getProfitAbility())+"<br />"+getConclusion(financeEvaluate.getProfitAbilityConclusion());
                            listFinanceGradeRespVO.setProfitAbilityConclusion(profitAbilityConclusion);//盈利能力分析结论
                            financeGradeEvaluateRespVO.setCurrentRate(getSpeechcraftByType(financeEvaluate.getCurrentRate()));//流动比率
                            financeGradeEvaluateRespVO.setQuickRate(getSpeechcraftByType(financeEvaluate.getQuickRate()));//速动比率
                            financeGradeEvaluateRespVO.setLoar(getSpeechcraftByType(financeEvaluate.getLoar()));//资产负债率
                            financeGradeEvaluateRespVO.setEbitMultiple(getSpeechcraftByType(financeEvaluate.getEbitMultiple()));//EBIT利息保障倍数
                            String solvencyConclusion = getSpeechcraftByContent(financeEvaluate.getSolvency())+"<br />"+getConclusion(financeEvaluate.getSolvencyConclusion());
                            listFinanceGradeRespVO.setSolvencyConclusion(solvencyConclusion);//偿债能力分析结论
                            financeGradeEvaluateRespVO.setReceivableRate(getSpeechcraftByType(financeEvaluate.getReceivableRate()));//应收款项周转率
                            financeGradeEvaluateRespVO.setInventoryTurnover(getSpeechcraftByType(financeEvaluate.getInventoryTurnover()));//存货周转率
                            financeGradeEvaluateRespVO.setCirculatingRate(getSpeechcraftByType(financeEvaluate.getCirculatingRate()));//流动资产周转率
                            financeGradeEvaluateRespVO.setTotalAssetRate(getSpeechcraftByType(financeEvaluate.getTotalAssetRate()));//总资产周转率
                            String operationAbilityConclusion = getSpeechcraftByContent(financeEvaluate.getOperationAbility())+"<br />"+getConclusion(financeEvaluate.getOperationAbilityConclusion());
                            listFinanceGradeRespVO.setOperationAbilityConclusion(operationAbilityConclusion);//营运能力分析结论
                            financeGradeEvaluateRespVO.setSalesGrow(getSpeechcraftByType(financeEvaluate.getSalesGrow()));//销售（营业）增长率
                            financeGradeEvaluateRespVO.setProfitGrow(getSpeechcraftByType(financeEvaluate.getProfitGrow()));//销售（营业）利润增长率
                            financeGradeEvaluateRespVO.setTotalAssetGrow(getSpeechcraftByType(financeEvaluate.getTotalAssetGrow()));//总资产增长率
                            financeGradeEvaluateRespVO.setCapitalGrow(getSpeechcraftByType(financeEvaluate.getCapitalGrow()));//资本保值增长率
                            String growAbilityConclusion = getSpeechcraftByContent(financeEvaluate.getGrowAbility())+"<br />"+getConclusion(financeEvaluate.getGrowAbilityConclusion());
                            listFinanceGradeRespVO.setGrowAbilityConclusion(growAbilityConclusion);//成长能力分析结论
                            financeGradeEvaluateRespVO.setCashDebt(getSpeechcraftByType(financeEvaluate.getCashDebt()));//经营性净现金流／流动负债
                            financeGradeEvaluateRespVO.setCashTotalDebt(getSpeechcraftByType(financeEvaluate.getCashTotalDebt()));//经营性净现金流／总负债
                            financeGradeEvaluateRespVO.setCashProfits(getSpeechcraftByType(financeEvaluate.getCashProfits()));//经营性现金流／净利润
                            String cashConclusion = getSpeechcraftByContent(financeEvaluate.getCash())+"<br />"+getConclusion(financeEvaluate.getCashConclusion());
                            listFinanceGradeRespVO.setCashConclusion(cashConclusion);//现金流量分析结论
                            listFinanceGradeEvaluateRespVO.add(financeGradeEvaluateRespVO);
                            listFinanceGradeRespVO.setListFinanceGradeEvaluateRespVO(listFinanceGradeEvaluateRespVO);
                        }else{
                            List<ListFinanceGradeEvaluateRespVO> listFinanceGradeEvaluateRespVO = new ArrayList<>();
                            ListFinanceGradeEvaluateRespVO financeGradeEvaluateRespVO = new ListFinanceGradeEvaluateRespVO();
                            financeGradeEvaluateRespVO.setCapitalGrow(null);
                            listFinanceGradeEvaluateRespVO.add(financeGradeEvaluateRespVO);
                            List<ListFinanceGradeAvgRespVO> listFinanceGradeAvgRespVO = new ArrayList<>();
                            listFinanceGradeRespVO.setListFinanceGradeEvaluateRespVO(listFinanceGradeEvaluateRespVO);
                            ListFinanceGradeAvgRespVO  financeGradeAvgRespVO = new ListFinanceGradeAvgRespVO();
                            financeGradeAvgRespVO.setCashProfits(null);
                            listFinanceGradeAvgRespVO.add(financeGradeAvgRespVO);
                            listFinanceGradeRespVO.setListFinanceGradeAvgRespVO(listFinanceGradeAvgRespVO);
                        }
                        //财务综合评分详情行业平均值
                        List<ListFinanceGradeAvgRespVO> listFinanceGradeAvgRespVO = new ArrayList<>();
                        ListFinanceGradeAvgRespVO  financeGradeAvgRespVO = new ListFinanceGradeAvgRespVO();
                        IndustryPerformance industryPerformance = industryPerformanceService.queryById(financeEvaluate.getIndustryAvgId());
                        if(industryPerformance != null){
                            financeGradeAvgRespVO.setYear(industryPerformance.getRptDate());//年份
                            financeGradeAvgRespVO.setTotalRoa(industryPerformance.getFaRoa2());//总资产报酬率
                            financeGradeAvgRespVO.setNetRoa(industryPerformance.getFaRoa2());//净资产收益率
                            financeGradeAvgRespVO.setSalesMargin(industryPerformance.getFaNetprofitmargin());//主营业务利润率
                            financeGradeAvgRespVO.setNetMargin(industryPerformance.getFaRpc());//成本费用利润率
                            financeGradeAvgRespVO.setCurrentRate(currentRateavg);//流动比率（行业平均值:1.3）
                            financeGradeAvgRespVO.setQuickRate(industryPerformance.getFaQuick());//速动比率
                            financeGradeAvgRespVO.setLoar(industryPerformance.getFaDebttoassets());//资产负债率
                            financeGradeAvgRespVO.setEbitMultiple(industryPerformance.getFaEbittointerest());//已获利息倍数
                            financeGradeAvgRespVO.setReceivableRate(industryPerformance.getFaArturn());//应收账款周转率
                            financeGradeAvgRespVO.setInventoryTurnover(industryPerformance.getFaInvturn());//存货周转率
                            financeGradeAvgRespVO.setCirculatingRate(industryPerformance.getFaCaturn());//流动资产周转率
                            financeGradeAvgRespVO.setTotalAssetRate(industryPerformance.getFaAssetsturn());//总资产周转率
                            financeGradeAvgRespVO.setSalesGrow(industryPerformance.getFaYoyOr());//销售增长率
                            financeGradeAvgRespVO.setProfitGrow(industryPerformance.getFaYoyOp());//销售利润增长率
                            financeGradeAvgRespVO.setTotalAssetGrow(industryPerformance.getFaYoyAssets());//总资产增长率
                            financeGradeAvgRespVO.setCapitalGrow(industryPerformance.getFaYoyCapital());//资本积累率
                            financeGradeAvgRespVO.setCashDebt(industryPerformance.getFaOcftoshortdebt());//现金流动负债比率(经营性净现金流/流动负债)
                            financeGradeAvgRespVO.setCashTotalDebt(industryPerformance.getFaCfa());//资产现金回收率(经营性净现金流／总产总额)
                            financeGradeAvgRespVO.setCashProfits(industryPerformance.getFaSccr());//盈余现金保障倍数(经营性现金流／净利润)
                            listFinanceGradeAvgRespVO.add(financeGradeAvgRespVO);
                            listFinanceGradeRespVO.setListFinanceGradeAvgRespVO(listFinanceGradeAvgRespVO);
                        }
                        else{
                            financeGradeAvgRespVO.setCashProfits(null);
                            listFinanceGradeAvgRespVO.add(financeGradeAvgRespVO);
                            listFinanceGradeRespVO.setListFinanceGradeAvgRespVO(listFinanceGradeAvgRespVO);
                        }
                    }
                }else{
                    List<ListFinanceGradeEvaluateRespVO> listFinanceGradeEvaluateRespVO = new ArrayList<>();
                    ListFinanceGradeEvaluateRespVO financeGradeEvaluateRespVO = new ListFinanceGradeEvaluateRespVO();
                    financeGradeEvaluateRespVO.setCapitalGrow(null);
                    listFinanceGradeEvaluateRespVO.add(financeGradeEvaluateRespVO);
                    List<ListFinanceGradeAvgRespVO> listFinanceGradeAvgRespVO = new ArrayList<>();
                    ListFinanceGradeAvgRespVO  financeGradeAvgRespVO = new ListFinanceGradeAvgRespVO();
                    financeGradeAvgRespVO.setCashProfits(null);
                    listFinanceGradeAvgRespVO.add(financeGradeAvgRespVO);
                    listFinanceGradeRespVO.setListFinanceGradeAvgRespVO(listFinanceGradeAvgRespVO);
                    listFinanceGradeRespVO.setListFinanceGradeEvaluateRespVO(listFinanceGradeEvaluateRespVO);
                }
            }
        }
        else{
            financeGradeValueRespVO.setCapitalGrow(null);
            listFinanceGradeValueRespVO.add(financeGradeValueRespVO);
            List<ListFinanceGradeEvaluateRespVO> listFinanceGradeEvaluateRespVO = new ArrayList<>();
            ListFinanceGradeEvaluateRespVO financeGradeEvaluateRespVO = new ListFinanceGradeEvaluateRespVO();
            financeGradeEvaluateRespVO.setCapitalGrow(null);
            listFinanceGradeEvaluateRespVO.add(financeGradeEvaluateRespVO);
            List<ListFinanceGradeAvgRespVO> listFinanceGradeAvgRespVO = new ArrayList<>();
            ListFinanceGradeAvgRespVO  financeGradeAvgRespVO = new ListFinanceGradeAvgRespVO();
            financeGradeAvgRespVO.setCashProfits(null);
            listFinanceGradeAvgRespVO.add(financeGradeAvgRespVO);
            listFinanceGradeRespVO.setListFinanceGradeAvgRespVO(listFinanceGradeAvgRespVO);
            listFinanceGradeRespVO.setListFinanceGradeEvaluateRespVO(listFinanceGradeEvaluateRespVO);
            listFinanceGradeRespVO.setListFinanceGradeValueRespVO(listFinanceGradeValueRespVO);
        }
        List<ListFinanceGradeRespVO> list = new ArrayList<>();
        list.add(listFinanceGradeRespVO);
        return list;
    }


    /**
     * 评分详情走势图
     */
    public List<ListFinanceGradeTrendRespRespVO> getFinanceGradeTrendRespVO(CompFinanceTrendReqVO req) {
        if (!(req.getCompId() > 0L)) {
            throw new IirException(IirErrorType.INTFACE_PARAMS_ERROR, "ID");
        }
        CompFinanceGrade compFinanceGrade = new CompFinanceGrade();
        List<ListFinanceGradeTrendRespRespVO> resp = new ArrayList<>();
        ListFinanceGradeTrendRespRespVO financeGradeTrendRespRespVO = new ListFinanceGradeTrendRespRespVO();
        List<ListFinanceGradeTrendValueRespRespVO> lists = new ArrayList<>();
        List<ListFinanceGradeAvgRespVO> listFinanceGradeAvg = new ArrayList<>();
        compFinanceGrade.setCompId(req.getCompId());
        compFinanceGrade.setStatus(Constant.DEFAULT_STATUS_NORMAL);
        List<Integer> years = getFinanceGradeByYear5();
        for(int year:years){
            compFinanceGrade.setYear(year);
            List<CompFinanceGrade> compFinanceGradeList = compFinanceGradeService.queryList(compFinanceGrade);
            if(compFinanceGradeList != null && !compFinanceGradeList.isEmpty()){
                    List<ListFinanceGradeTrendValueRespRespVO> listFinanceGradeTrendValueRespRespVO = gerListFinanceGradeTrendValueRespRespVO(
                            compFinanceGradeList.get(0));
                    for (ListFinanceGradeTrendValueRespRespVO financeGradeTrendValueRespRespVO : listFinanceGradeTrendValueRespRespVO) {
                        lists.add(financeGradeTrendValueRespRespVO);
                    }
    
                    IndustryPerformance industryPerformance = industryPerformanceService
                            .queryAvgList(compFinanceGradeList.get(0).getId());
                    if (industryPerformance != null) {
                        ListFinanceGradeAvgRespVO listFinanceGradeAvgRespVO = getListFinanceGradeAvgRespVO(
                                industryPerformance);
                        if (listFinanceGradeAvgRespVO != null) {
                            listFinanceGradeAvg.add(listFinanceGradeAvgRespVO);
                        }
                    }
                    financeGradeTrendRespRespVO.setListFinanceGradeAvgRespVO(listFinanceGradeAvg);
            }
            else{
                ListFinanceGradeTrendValueRespRespVO financeGradeTrendValueRespRespVO = new ListFinanceGradeTrendValueRespRespVO();
                financeGradeTrendValueRespRespVO.setCompId(req.getCompId());
                financeGradeTrendValueRespRespVO.setYear(year);
                lists.add(financeGradeTrendValueRespRespVO);
            }
        }
        financeGradeTrendRespRespVO.setListFinanceGradeTrendValueRespRespVO(lists);
        resp.add(financeGradeTrendRespRespVO);
        return resp;
    }
    
    /**
     * 评分详情走势图行业平均值
     */
    public ListFinanceGradeAvgRespVO getListFinanceGradeAvgRespVO(IndustryPerformance industryPerformance){
        ListFinanceGradeAvgRespVO  financeGradeAvgRespVO = new ListFinanceGradeAvgRespVO();
        if(industryPerformance != null){
            financeGradeAvgRespVO.setYear(industryPerformance.getRptDate());//年份
            financeGradeAvgRespVO.setTotalRoa(industryPerformance.getFaRoa2());//总资产报酬率
            financeGradeAvgRespVO.setNetRoa(industryPerformance.getFaRoa2());//净资产收益率
            financeGradeAvgRespVO.setSalesMargin(industryPerformance.getFaNetprofitmargin());//主营业务利润率
            financeGradeAvgRespVO.setNetMargin(industryPerformance.getFaRpc());//成本费用利润率
            financeGradeAvgRespVO.setCurrentRate(currentRateavg);//流动比率（行业平均值:1.3）
            financeGradeAvgRespVO.setQuickRate(industryPerformance.getFaQuick());//速动比率
            financeGradeAvgRespVO.setLoar(industryPerformance.getFaDebttoassets());//资产负债率
            financeGradeAvgRespVO.setEbitMultiple(industryPerformance.getFaEbittointerest());//已获利息倍数
            financeGradeAvgRespVO.setReceivableRate(industryPerformance.getFaArturn());//应收账款周转率
            financeGradeAvgRespVO.setInventoryTurnover(industryPerformance.getFaInvturn());//存货周转率
            financeGradeAvgRespVO.setCirculatingRate(industryPerformance.getFaCaturn());//流动资产周转率
            financeGradeAvgRespVO.setTotalAssetRate(industryPerformance.getFaAssetsturn());//总资产周转率
            financeGradeAvgRespVO.setSalesGrow(industryPerformance.getFaYoyOr());//销售增长率
            financeGradeAvgRespVO.setProfitGrow(industryPerformance.getFaYoyOp());//销售利润增长率
            financeGradeAvgRespVO.setTotalAssetGrow(industryPerformance.getFaYoyAssets());//总资产增长率
            financeGradeAvgRespVO.setCapitalGrow(industryPerformance.getFaYoyCapital());//资本积累率
            financeGradeAvgRespVO.setCashDebt(industryPerformance.getFaOcftoshortdebt());//现金流动负债比率(经营性净现金流/流动负债)
            financeGradeAvgRespVO.setCashTotalDebt(industryPerformance.getFaCfa());//资产现金回收率(经营性净现金流／总产总额)
            financeGradeAvgRespVO.setCashProfits(industryPerformance.getFaSccr());//盈余现金保障倍数(经营性现金流／净利润)
            
        }
        return financeGradeAvgRespVO;
    }
    
    /**
     *财务综合评分详情指标值
     */
    public List<ListFinanceGradeTrendValueRespRespVO> gerListFinanceGradeTrendValueRespRespVO(CompFinanceGrade financeGrade){
        List<ListFinanceGradeTrendValueRespRespVO> resp = new ArrayList<>();
        ListFinanceGradeTrendValueRespRespVO financeGradeTrendValueRespRespVO = new ListFinanceGradeTrendValueRespRespVO();
        
        if(financeGrade != null){
            financeGradeTrendValueRespRespVO.setId(financeGrade.getId());//Id
            financeGradeTrendValueRespRespVO.setCompId(financeGrade.getCompId());//公司Id
            financeGradeTrendValueRespRespVO.setYear(financeGrade.getYear());//年份
            financeGradeTrendValueRespRespVO.setTotalRoa(financeGrade.getTotalRoa());//总资产报酬率
            financeGradeTrendValueRespRespVO.setNetRoa(financeGrade.getNetRoa());//净资产收益率
            financeGradeTrendValueRespRespVO.setSalesMargin(financeGrade.getSalesMargin());//销售（营业）利润率
            financeGradeTrendValueRespRespVO.setNetMargin(financeGrade.getNetMargin());//成本费用利润率
            financeGradeTrendValueRespRespVO.setCurrentRate(financeGrade.getCurrentRate());//流动比率
            financeGradeTrendValueRespRespVO.setQuickRate(financeGrade.getQuickRate());//速动比率
            financeGradeTrendValueRespRespVO.setLoar(financeGrade.getLoar());//资产负债率
            financeGradeTrendValueRespRespVO.setEbitMultiple(financeGrade.getEbitMultiple());//利息保障倍数
            financeGradeTrendValueRespRespVO.setReceivableRate(financeGrade.getReceivableRate());//应收款项周转率
            financeGradeTrendValueRespRespVO.setInventoryTurnover(financeGrade.getInventoryTurnover());//存货周转率
            financeGradeTrendValueRespRespVO.setCirculatingRate(financeGrade.getCirculatingRate());//流动资产周转率
            financeGradeTrendValueRespRespVO.setTotalAssetRate(financeGrade.getTotalAssetRate());//总资产周转率
            financeGradeTrendValueRespRespVO.setSalesGrow(financeGrade.getSalesGrow());//销售（营业）增长率
            financeGradeTrendValueRespRespVO.setProfitGrow(financeGrade.getProfitGrow());//销售（营业）利润增长率
            financeGradeTrendValueRespRespVO.setTotalAssetGrow(financeGrade.getTotalAssetGrow());//总资产增长率
            financeGradeTrendValueRespRespVO.setCapitalGrow(financeGrade.getCapitalGrow());//资本保值增长率
            financeGradeTrendValueRespRespVO.setCashDebt(financeGrade.getCashDebt());//经营性净现金流／流动负债
            financeGradeTrendValueRespRespVO.setCashTotalDebt(financeGrade.getCashTotalDebt());//经营性净现金流／总产总额
            financeGradeTrendValueRespRespVO.setCashProfits(financeGrade.getCashProfits());//经营性现金流／净利润
            resp.add(financeGradeTrendValueRespRespVO);
        }
        return resp;
    }
    
    /**
     * 同业对比
     */
    public List<ListContrastRespVO> getContrastRespVO(ListContrastReqVO req) {
        List<ListContrastRespVO> resp = new ArrayList<>();
        List<ListCompareCompaniesRespVO> listCompareCompaniesRespVO = new ArrayList<>();
        String[] compIds = req.getCompId().split(",");
        if(compIds.length <= 0){
            throw new IirException(IirErrorType.INTFACE_PARAMS_ERROR, "CompId");
        }
        List<Long> comIdList = new ArrayList<>();
        for(String stringCompId:compIds) {
            Long compId = Long.parseLong(stringCompId);
            comIdList.add(compId);
        }
        //查询公司数据
        List<Company> companys = companyService.listByIds(comIdList);
        //查询财务综合评分
        List<Integer> years = getFinanceGradeByYear();
        List<CompFinanceGrade> compFinanceGradeList = compFinanceGradeService.queryCompYears(comIdList,years);
        //查询中国A股日行情估值指标
        List<ShareIndicatorIndex> siiList = shareIndicatorIndexService.queryByStock(comIdList,years);
        //查询中国A股财务衍生指标表
        List<ShareFinancialIndex> sfiList = shareFinancialIndexService.queryByStock(comIdList,years);
        
        for(Long compId:comIdList) {
            Company company = new Company();
            for(Company obj : companys){
                if(obj.getId().equals(compId)){
                    company = obj;
                    break;
                }
            }

            for (int year : years) {
                CompFinanceGrade compFinanceGrade = null;
                for (CompFinanceGrade financeGrade : compFinanceGradeList) {
                    if(financeGrade.getCompId().equals(compId) && financeGrade.getYear().equals(year)){
                        compFinanceGrade = financeGrade;
                        break;
                    }
                }
                if(null != compFinanceGrade) {
                    ListCompareCompaniesRespVO compareCompaniesRespVO = getCompareCompaniesRespVO(compFinanceGrade);
                    if(company != null) {
                        compareCompaniesRespVO.setName(company.getName());
                    }
                    listCompareCompaniesRespVO.add(compareCompaniesRespVO);
                }
                else {
                    ListCompareCompaniesRespVO compareCompaniesRespVO = new ListCompareCompaniesRespVO();
                    compareCompaniesRespVO.setCompId(compId);
                    compareCompaniesRespVO.setYear(year);
                    if (company != null) {
                        compareCompaniesRespVO.setName(company.getName());
                    }
                    listCompareCompaniesRespVO.add(compareCompaniesRespVO);
                }
                
                //处理每股指标
                for(ShareIndicatorIndex sii : siiList) {
                    if (sii.getCompId().equals(compId) && sii.getTradeDt().substring(0,4).equals(year)) {
                        ListCompareCompaniesRespVO compareCompaniesRespVO = listCompareCompaniesRespVO
                                .get(listCompareCompaniesRespVO.size() - 1);
                        compareCompaniesRespVO.setPe(sii.getValPe());
                        compareCompaniesRespVO.setPb(sii.getValPbNew());
                        compareCompaniesRespVO.setPs(sii.getValPs());
                        compareCompaniesRespVO.setPcf(sii.getValPcfNcf());
                        listCompareCompaniesRespVO.set(listCompareCompaniesRespVO.size() - 1, compareCompaniesRespVO);
                        break;
                    }
                }
                
                for(ShareFinancialIndex sfi : sfiList){
                    if(sfi.getCompId().equals(compId) && sfi.getFiscalyear().equals(year)){
                        ListCompareCompaniesRespVO compareCompaniesRespVO = listCompareCompaniesRespVO.get(listCompareCompaniesRespVO.size() - 1);
                        compareCompaniesRespVO.setShare(sfi.getEpsBasic());
                        compareCompaniesRespVO.setAfter(sfi.getEpsDiluted3());
                        listCompareCompaniesRespVO.set(listCompareCompaniesRespVO.size() - 1,compareCompaniesRespVO);
                        break;
                    }
                }

            }
        }
        ListUtil<ListContrastRespVO> listUtil = BeanUtils.instantiateClass(ListUtil.class);
        listUtil.copyList(listCompareCompaniesRespVO, resp, ListContrastRespVO.class);
        return resp;
    }


    /**
     * 同业对比数据
     */
    public ListCompareCompaniesRespVO getCompareCompaniesRespVO(CompFinanceGrade financeGrade) {
        ListCompareCompaniesRespVO listCompareCompaniesRespVO = new ListCompareCompaniesRespVO();
        if(financeGrade != null){
            listCompareCompaniesRespVO.setId(financeGrade.getId());//Id
            listCompareCompaniesRespVO.setCompId(financeGrade.getCompId());//公司Id
            listCompareCompaniesRespVO.setYear(financeGrade.getYear());//年份
            listCompareCompaniesRespVO.setTotalRoa(financeGrade.getTotalRoa());//总资产收益率ROA
            listCompareCompaniesRespVO.setNetRoa(financeGrade.getNetRoa());//净资产收益率ROE
            listCompareCompaniesRespVO.setRateMargin(financeGrade.getRateMargin());//毛利率
            listCompareCompaniesRespVO.setNetProfit(financeGrade.getNetProfit());//净利率
            listCompareCompaniesRespVO.setCurrentRate(financeGrade.getCurrentRate());//流动比率
            listCompareCompaniesRespVO.setQuickRate(financeGrade.getQuickRate());//速动比率
            listCompareCompaniesRespVO.setCashRatio(financeGrade.getCashRatio());//现金比率
            listCompareCompaniesRespVO.setLoar(financeGrade.getLoar());//资产负债率
            listCompareCompaniesRespVO.setLongTermAssetRatio(financeGrade.getLongTermAssetRatio());//所有者权益比率
            listCompareCompaniesRespVO.setEbitMultiple(financeGrade.getEbitMultiple());//EBIT利息保障倍数
            listCompareCompaniesRespVO.setInventoryTurnover(financeGrade.getInventoryTurnover());//存货周转率
            listCompareCompaniesRespVO.setReceivableRate(financeGrade.getReceivableRate());//应收款项周转率
            listCompareCompaniesRespVO.setCirculatingRate(financeGrade.getCirculatingRate());//流动资产周转率
            listCompareCompaniesRespVO.setFixAssetDays(financeGrade.getFixAssetDays());//固定资产周转率
            listCompareCompaniesRespVO.setTotalAssetRate(financeGrade.getTotalAssetRate());//总资产周转率
            listCompareCompaniesRespVO.setSalesGrow(financeGrade.getSalesGrow());//主营业务收入增长率
            listCompareCompaniesRespVO.setNetProfitRatio(financeGrade.getNetProfitRatio());//净利润增长率
            listCompareCompaniesRespVO.setTotalAssetGrow(financeGrade.getTotalAssetGrow());//总资产增长率
            listCompareCompaniesRespVO.setCapitalGrow(financeGrade.getCapitalGrow());//资本保值增长率
            listCompareCompaniesRespVO.setCashOutflow(financeGrade.getCashOutflow());//经营性净现金流/总现金流出
            listCompareCompaniesRespVO.setCashTotalDebt(financeGrade.getCashTotalDebt());//经营性净现金流／总负债
            listCompareCompaniesRespVO.setOperatingIncome(financeGrade.getOperatingIncome());//经营性现金流／销售收入
            listCompareCompaniesRespVO.setNetCashRecoveryRatio(financeGrade.getNetCashRecoveryRatio());//经营性净现金流／资产总额

        }
        return listCompareCompaniesRespVO;
    }
    
    
    /**
     * 同业对比走势图
     */
    public List<ListContrastTrendRespVO> getContrastTrendRespVO(ListContrastTrendReqVO req) {
        List<ListContrastTrendRespVO> resp = new ArrayList<>();
        ListContrastTrendRespVO contrastTrendRespVO = new ListContrastTrendRespVO();
        List<ListContrastTrendDataRespVO> lists = new ArrayList<>();
        List<ListContrastTrendDataRespVO> listContrastTrendRespVO = new ArrayList<>();
        List<ListContrastTrendAverageRespVO> listContrastTrendAverage = new ArrayList<>();
        String[] compIds = req.getCompId().split(",");
        for(String stringCompId:compIds) {
            Long compId = Long.parseLong(stringCompId);
            if (!(compId > 0L)) {
                throw new IirException(IirErrorType.INTFACE_PARAMS_ERROR, "ID");
            }
                List<CompFinanceGrade> compFinanceGradeList = new ArrayList<>();
                CompFinanceGrade compFinanceGrade = new CompFinanceGrade();
                compFinanceGrade.setCompId(compId);
                compFinanceGrade.setStatus(Constant.DEFAULT_STATUS_NORMAL);
                List<Integer> years = getFinanceGradeByYear5();
                for(int year:years){
                    compFinanceGrade.setYear(year);
                    compFinanceGradeList = compFinanceGradeService.queryList(compFinanceGrade);
                    if(compFinanceGradeList != null && !compFinanceGradeList.isEmpty()) {
                            ListContrastTrendDataRespVO contrastTrendDataRespVO = getContrastTrendDateRespVO(compFinanceGradeList.get(0));
                            listContrastTrendRespVO.add(contrastTrendDataRespVO);
                            if(compFinanceGradeList.get(0).getCompId().equals(Long.parseLong(compIds[0]))){
                                IndustryPerformance industryPerformance = industryPerformanceService.queryAvgList(compFinanceGradeList.get(0).getId());
                                if (industryPerformance != null) {
                                    ListContrastTrendAverageRespVO contrastTrendAverageRespVO =  getListContrastTrendAverageRespVO(industryPerformance);
                                        listContrastTrendAverage.add(contrastTrendAverageRespVO);
                                }else{
                                    ListContrastTrendAverageRespVO contrastTrendAverageRespVO =  new ListContrastTrendAverageRespVO();
                                    contrastTrendAverageRespVO.setYear(Integer.toString(year));
                                    listContrastTrendAverage.add(contrastTrendAverageRespVO);
                                }
                                contrastTrendRespVO.setListContrastTrendAverageRespVO(listContrastTrendAverage);
                            }
                    }else{
                        ListContrastTrendDataRespVO contrastTrendDataRespVO = new ListContrastTrendDataRespVO();
                        contrastTrendDataRespVO.setCompId(compId);
                        contrastTrendDataRespVO.setYear(year);
                        Company company = companyService.queryById(compId);
                        if(company != null){
                            contrastTrendDataRespVO.setName(company.getName());
                        }
                        listContrastTrendRespVO.add(contrastTrendDataRespVO);
                    }
                }
                
        }
        contrastTrendRespVO.setListContrastTrendDataRespVO(listContrastTrendRespVO);
        resp.add(contrastTrendRespVO);
        return resp;
    }
    
    /**
     *同业对比走势图行业平均值
     */
    public ListContrastTrendAverageRespVO getListContrastTrendAverageRespVO(IndustryPerformance industryPerformance){
        ListContrastTrendAverageRespVO contrastTrendAverageRespVO = new ListContrastTrendAverageRespVO();
        if(industryPerformance != null){
            contrastTrendAverageRespVO.setYear(industryPerformance.getRptDate());//年份
            contrastTrendAverageRespVO.setTotalRoa(industryPerformance.getFaRoa2());//总资产报酬率
            contrastTrendAverageRespVO.setNetRoa(industryPerformance.getFaRoe());//净资产收益率
            contrastTrendAverageRespVO.setCurrentRate(currentRateavg);//流动比率（行业平均值:1.3）
            contrastTrendAverageRespVO.setQuickRate(industryPerformance.getFaQuick());//速动比率
            contrastTrendAverageRespVO.setLoar(industryPerformance.getFaDebttoassets());//资产负债率
            contrastTrendAverageRespVO.setEbitMultiple(industryPerformance.getFaEbittointerest());//已获利息倍数
            contrastTrendAverageRespVO.setReceivableRate(industryPerformance.getFaArturn());//应收账款周转率
            contrastTrendAverageRespVO.setInventoryTurnover(industryPerformance.getFaInvturn());//存货周转率
            contrastTrendAverageRespVO.setCirculatingRate(industryPerformance.getFaCaturn());//流动资产周转率
            contrastTrendAverageRespVO.setTotalAssetRate(industryPerformance.getFaAssetsturn());//总资产周转率
            contrastTrendAverageRespVO.setTotalAssetGrow(industryPerformance.getFaYoyAssets());//总资产增长率
            contrastTrendAverageRespVO.setNetCashRecoveryRatio(industryPerformance.getFaCfa());//资产现金回收率(经营性净现金流／总产总额)
            contrastTrendAverageRespVO.setOperatingIncome(industryPerformance.getFaSccr());//盈余现金保障倍数(经营性现金流／净利润)
        }
        return contrastTrendAverageRespVO;
    }


    /**
     * 同业对比走势图公司数据
     */
    public ListContrastTrendDataRespVO getContrastTrendDateRespVO(CompFinanceGrade financeGrade) {
        ListContrastTrendDataRespVO listContrastTrendDataRespVO = new ListContrastTrendDataRespVO();
        if(financeGrade != null){
            listContrastTrendDataRespVO.setId(financeGrade.getId());//Id
            listContrastTrendDataRespVO.setCompId(financeGrade.getCompId());//公司Id
            listContrastTrendDataRespVO.setYear(financeGrade.getYear());//年份
            listContrastTrendDataRespVO.setTotalRoa(financeGrade.getTotalRoa());//总资产收益率ROA
            listContrastTrendDataRespVO.setNetRoa(financeGrade.getNetRoa());//净资产收益率ROE
            listContrastTrendDataRespVO.setRateMargin(financeGrade.getRateMargin());//毛利率
            listContrastTrendDataRespVO.setNetProfit(financeGrade.getNetProfit());//净利率
            listContrastTrendDataRespVO.setCurrentRate(financeGrade.getCurrentRate());//流动比率
            listContrastTrendDataRespVO.setQuickRate(financeGrade.getQuickRate());//速动比率
            listContrastTrendDataRespVO.setCashRatio(financeGrade.getCashRatio());//现金比率
            listContrastTrendDataRespVO.setLoar(financeGrade.getLoar());//资产负债率
            listContrastTrendDataRespVO.setLongTermAssetRatio(financeGrade.getLongTermAssetRatio());//所有者权益比率
            listContrastTrendDataRespVO.setEbitMultiple(financeGrade.getEbitMultiple());//EBIT利息保障倍数
            listContrastTrendDataRespVO.setInventoryTurnover(financeGrade.getInventoryTurnover());//存货周转率
            listContrastTrendDataRespVO.setReceivableRate(financeGrade.getReceivableRate());//应收款项周转率
            listContrastTrendDataRespVO.setCirculatingRate(financeGrade.getCirculatingRate());//流动资产周转率
            listContrastTrendDataRespVO.setFixAssetDays(financeGrade.getFixAssetDays());//固定资产周转率
            listContrastTrendDataRespVO.setTotalAssetRate(financeGrade.getTotalAssetRate());//总资产周转率
            listContrastTrendDataRespVO.setSalesGrow(financeGrade.getSalesGrow());//主营业务收入增长率
            listContrastTrendDataRespVO.setNetProfitRatio(financeGrade.getNetProfitRatio());//净利润增长率
            listContrastTrendDataRespVO.setTotalAssetGrow(financeGrade.getTotalAssetGrow());//总资产增长率
            listContrastTrendDataRespVO.setCapitalGrow(financeGrade.getCapitalGrow());//资本保值增长率
            listContrastTrendDataRespVO.setCashOutflow(financeGrade.getCashOutflow());//经营性净现金流/总现金流出
            listContrastTrendDataRespVO.setCashTotalDebt(financeGrade.getCashTotalDebt());//经营性净现金流／总负债
            listContrastTrendDataRespVO.setOperatingIncome(financeGrade.getOperatingIncome());//经营性现金流／销售收入
            listContrastTrendDataRespVO.setNetCashRecoveryRatio(financeGrade.getNetCashRecoveryRatio());//经营性净现金流／资产总额
            Company company = companyService.queryById(financeGrade.getCompId());
            if(company != null){
                listContrastTrendDataRespVO.setName(company.getName());
            }
        }
        return listContrastTrendDataRespVO;
    }
    
    /**
     * 判断字符串是否为数字
     */
    public static boolean isNumericZidai(String str) {
        for (int i = 0; i < str.length(); i++) {
            System.out.println(str.charAt(i));
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }
   
    
    /**
     * 评分详情
     * 模块评价（1 优秀，2 良好，3 中等，4 较低，5，6较差
     */
    public String getSpeechcraftByType(Long id){
        String type = null;
        if(null != id){
            Speechcraft speechcraft = speechcraftService.queryById(id);
            if(null != speechcraft){
                if(null != speechcraft.getType()){
                    if(speechcraft.getType()==1){
                        type="优秀";
                    }else if(speechcraft.getType()==2){
                        type="良好";
                    }else if(speechcraft.getType()==3){
                        type="中等";
                    }else if(speechcraft.getType()==4){
                        type="较低";
                    }else{
                        type="较差";
                    }
                }
            }
        }
        return type;
    }
    
    /**
     * 财务综合评分
     * 模块评价（1 优秀，2 良好，3 中等，4 较低，5，6较差
     * 模块解读
     */
    public String getSpeechcraftByContent(Long id){
        String content = "";
        if(null != id){
            Speechcraft speechcraft = speechcraftService.queryById(id);
            if(null != speechcraft){
                if(null != speechcraft.getContent()){
                    content = speechcraft.getContent();
                }
            }
        }
        return content;
    }
    
    
    /**
     * 分析结论
     */
    public String getConclusion(String conclusion){
        String con = " ";
        if(conclusion != null && !conclusion.equals("")){
            String[] cons = conclusion.split(";");
            con = cons[0];
            for(int i = 1; i < cons.length; i++){
                con = con +"<br />"+ cons[i];
            }
        }
        return con;
    }
    
    
    /**
     *获取5近年的年份
     */
    public List<Integer> getFinanceGradeByYear(){
        Calendar cal = Calendar.getInstance();
        List<Integer> years = new ArrayList<>();
        int year = cal.get(Calendar.YEAR);
        for(int i = 0; i < 5; i++){
            year= year-1;
            years.add(year);
        }
        return years;
    }
    
    /**
     *获取近3年的年份
     */
    public List<Integer> getFinanceGradeByYear3(){
        Calendar cal = Calendar.getInstance();
        List<Integer> years = new ArrayList<>();
        int year = cal.get(Calendar.YEAR);
        for(int i = 0; i < 3; i++){
            year= year-1;
            years.add(year);
        }
        return years;
    }
    
    /**
     *获取近5年的年份 从小到大排序
     */
    public List<Integer> getFinanceGradeByYear5(){
        Calendar cal = Calendar.getInstance();
        List<Integer> years = new ArrayList<>();
        List<Integer> y = new ArrayList<>();
        int year = cal.get(Calendar.YEAR);
        for(int i = 0; i < 5; i++){
            year= year-1;
            years.add(year);
        }
        for(int i=years.size()-1;i>=0;i--){
            y.add(years.get(i));
        }
        return y;
    }
    
    /**
     *获取10近年的年份
     */
    public List<Integer> getFinanceGradeByYear10(){
        Calendar cal = Calendar.getInstance();
        List<Integer> years = new ArrayList<>();
        int year = cal.get(Calendar.YEAR);
        for(int i = 0; i < 10; i++){
            year= year-1;
            years.add(year);
        }
        return years;
    }
    
    /**
     *获取近10年的年份
     */
    public List<Integer> getFinanceGradeByYear(int number){
        Calendar cal = Calendar.getInstance();
        List<Integer> years = new ArrayList<>();
        int year = cal.get(Calendar.YEAR);
        for(int i = 0; i < number; i++){
            year= year-1;
            years.add(year);
        }
        return years;
    }
    
   
    
}
